package com.tanhua.server.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MVC的配置类:注册拦截器
 * 实现WebMvcConfigurer
 * 需要声明一下 是配置类
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 把拦截器注入到Mvc当中去
     * @param registry
     */
    @Autowired
    private TokenInterceptor tokenInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(tokenInterceptor)//添加拦截器
        .addPathPatterns("/**")//当前拦截器处理所有的url
        .excludePathPatterns(new String[]{"/user/login","/user/loginVerification"});//除去验证码登陆和接口
    }
}
